home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c
- Subject: Re: routine for yesterday's date
- Date: Mon, 01 Apr 1996 04:05:52 GMT
- Organization: Netcom
- Message-ID: <315f54bc.483131085@nntp.ix.netcom.com>
- References: <315c4d0f.19874776@ottnews.shl.com> <1996Mar30.043002.19054@sq.com> <Dp3B56.FKI@alisa.org>
- NNTP-Posting-Host: ix-dc10-09.ix.netcom.com
- X-NETCOM-Date: Sun Mar 31 8:05:40 PM PST 1996
- X-Newsreader: Forte Agent .99d/32.182
-
- wjjr@alisa.org (John J. Rushford) wrote:
-
- > Mark Brader (msb@sq.com) wrote:
- > : Bruce Coghill (75323.455@compuserve.com) writes at 2:48 PM, March 29, 1996:
- > :
- > : > In my C manual the time.h and time functions are described
- > : > and how I can pull off each element in the structure (like year,
- > : > month, day, day-of-the-year), but it isn't clear to me how to subtract
- > : > a day.
- >
- > : This is question 13.14 on the FAQ list, but I'd like to expand a bit
- > : on what it says there.
- >
- > : Bruce, you have gotten as far as calling time() and localtime(). The
- > : next thing is to use the normalizing feature of mktime(). Suppose that
- > : you have a variable of type struct tm called x, and you've just put the
- > : current time into it using localtime(). Now you basically just want to
- > : do something like this:
- >
- > : x.tm_day--; /* back 1 day */
- > : (void) mktime (&x); /* normalize */
- >
- > [stuff deleted]
- >
- > Why bother with mktime() when it is so much easier to use the following and
- > you don't have to bother with errors gotten from x.tm_day--;
- >
- > long ticks
- > struct tm * dt;
- >
- > time(&ticks);
- >
- > /* 86400 seconds in a day */
- > ticks -= 86400
- >
- > dt = localtime (&ticks);
-
- Let me make a wild guess as to why Mark suggested the method he did
- rather than your much simpler method. Perhaps it was because your
- code is illegal in standard C.
-
- time() taks a time_t*, not a long* as an argument. time_t may be any
- arithmetic type. Furthermore, nothing in the standard suggests that
- subtracting 86400 from a time_t does anything useful, let alone
- decrement the time by one day.
-
-
- Michael M Rubenstein
-